#!/usr/bin/env node
const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs');
const ejs = require('ejs');

inquirer
  .prompt([
    {
      type: 'input',
      name: 'name',
      message: 'Preject name',
    },
  ])
  .then(anwsers => {
    // 模板目录
    const templDir = path.join(__dirname, 'templetes');

    // 目标路径
    const destDir = process.cwd();

    fs.readdir(templDir, (err, files) => {
      if (err) throw err;
      files.forEach(file => {
        ejs.renderFile(path.join(templDir, file), anwsers, (err, result) => {
          if (err) throw err;
          fs.writeFileSync(path.join(destDir, file), result);
        });
      });
    });
  });
